package com.ala4.oxcafe.boot.page;

import com.ala4.oxcafe.export.ExportPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 分页数据
 *
 * @author ruoyi
 */
@Data
@Schema(description = "分页参数")
public class PageDomain implements ExportPage {
    /**
     * 当前记录起始索引
     */
    @Schema(description = "当前页", defaultValue = "1")
    private Integer pageNum = 1;

    /**
     * 每页显示记录数
     */
    @Schema(description = "每页数量", defaultValue = "10")
    private Integer pageSize = 20;

    /**
     * 排序列
     */
    @Schema(description = "排序列", defaultValue = "create_time")
    private String orderByColumn = "create_time";

    /**
     * 排序的方向desc或者asc
     */
    @Schema(description = "排序的方向desc或者asc", defaultValue = "desc")
    private String isAsc = "desc";


    @Schema(description = "是否进行count查询", defaultValue = "true")
    private Boolean searchCount = true;


    public <T> Page<T> toPlusPage() {
        Page<T> objectPage = Page.of(this.pageNum, this.pageSize);
        objectPage.setSearchCount(this.getSearchCount());
        return objectPage.addOrder(OrderItem.desc(this.orderByColumn));
    }

}
